package com.google.android.vending.licensing;

import android.text.TextUtils;
import android.util.Log;
import com.google.android.vending.licensing.util.Base64;
import com.google.android.vending.licensing.util.Base64DecoderException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;

class LicenseValidator
{
  private static final int ERROR_CONTACTING_SERVER = 257;
  private static final int ERROR_INVALID_PACKAGE_NAME = 258;
  private static final int ERROR_NON_MATCHING_UID = 259;
  private static final int ERROR_NOT_MARKET_MANAGED = 3;
  private static final int ERROR_OVER_QUOTA = 5;
  private static final int ERROR_SERVER_FAILURE = 4;
  private static final int LICENSED = 0;
  private static final int LICENSED_OLD_KEY = 2;
  private static final int NOT_LICENSED = 1;
  private static final String SIGNATURE_ALGORITHM = "SHA1withRSA";
  private static final String TAG = "LicenseValidator";
  private final LicenseCheckerCallback mCallback;
  private final DeviceLimiter mDeviceLimiter;
  private final int mNonce;
  private final String mPackageName;
  private final Policy mPolicy;
  private final String mVersionCode;

  LicenseValidator(Policy paramPolicy, DeviceLimiter paramDeviceLimiter, LicenseCheckerCallback paramLicenseCheckerCallback, int paramInt, String paramString1, String paramString2)
  {
    this.mPolicy = paramPolicy;
    this.mDeviceLimiter = paramDeviceLimiter;
    this.mCallback = paramLicenseCheckerCallback;
    this.mNonce = paramInt;
    this.mPackageName = paramString1;
    this.mVersionCode = paramString2;
  }

  private void handleApplicationError(int paramInt)
  {
    this.mCallback.applicationError(paramInt);
  }

  private void handleInvalidResponse()
  {
    this.mCallback.dontAllow(561);
  }

  private void handleResponse(int paramInt, ResponseData paramResponseData)
  {
    this.mPolicy.processServerResponse(paramInt, paramResponseData);
    if (this.mPolicy.allowAccess())
    {
      this.mCallback.allow(paramInt);
      return;
    }
    this.mCallback.dontAllow(paramInt);
  }

  public LicenseCheckerCallback getCallback()
  {
    return this.mCallback;
  }

  public int getNonce()
  {
    return this.mNonce;
  }

  public String getPackageName()
  {
    return this.mPackageName;
  }

  public void verify(PublicKey paramPublicKey, int paramInt, String paramString1, String paramString2)
  {
    Object localObject;
    String str;
    if ((paramInt != 0) && (paramInt != 1))
    {
      localObject = null;
      str = null;
      if (paramInt != 2);
    }
    else
    {
      try
      {
        Signature localSignature = Signature.getInstance("SHA1withRSA");
        localSignature.initVerify(paramPublicKey);
        if (paramString1 != null)
          localSignature.update(paramString1.getBytes());
        if ((paramString2 == null) || (!localSignature.verify(Base64.decode(paramString2))))
        {
          Log.e("LicenseValidator", "Signature verification failed.");
          handleInvalidResponse();
          return;
        }
      }
      catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
      {
        throw new RuntimeException(localNoSuchAlgorithmException);
      }
      catch (InvalidKeyException localInvalidKeyException)
      {
        handleApplicationError(5);
        return;
      }
      catch (SignatureException localSignatureException)
      {
        throw new RuntimeException(localSignatureException);
      }
      catch (Base64DecoderException localBase64DecoderException)
      {
        Log.e("LicenseValidator", "Could not Base64-decode signature.");
        handleInvalidResponse();
        return;
      }
      try
      {
        ResponseData localResponseData = ResponseData.parse(paramString1);
        localObject = localResponseData;
        if (localObject.responseCode != paramInt)
        {
          Log.e("LicenseValidator", "Response codes don't match.");
          handleInvalidResponse();
          return;
        }
      }
      catch (IllegalArgumentException localIllegalArgumentException)
      {
        Log.e("LicenseValidator", "Could not parse response.");
        handleInvalidResponse();
        return;
      }
      if (localObject.nonce != this.mNonce)
      {
        Log.e("LicenseValidator", "Nonce doesn't match.");
        handleInvalidResponse();
        return;
      }
      if (!localObject.packageName.equals(this.mPackageName))
      {
        Log.e("LicenseValidator", "Package name doesn't match.");
        handleInvalidResponse();
        return;
      }
      if (!localObject.versionCode.equals(this.mVersionCode))
      {
        Log.e("LicenseValidator", "Version codes don't match.");
        handleInvalidResponse();
        return;
      }
      str = localObject.userId;
      if (TextUtils.isEmpty(str))
      {
        Log.e("LicenseValidator", "User identifier is empty.");
        handleInvalidResponse();
        return;
      }
    }
    switch (paramInt)
    {
    default:
      Log.e("LicenseValidator", "Unknown response code for license check.");
      handleInvalidResponse();
      return;
    case 0:
    case 2:
      handleResponse(this.mDeviceLimiter.isDeviceAllowed(str), localObject);
      return;
    case 1:
      handleResponse(561, localObject);
      return;
    case 257:
      Log.w("LicenseValidator", "Error contacting licensing server.");
      handleResponse(291, localObject);
      return;
    case 4:
      Log.w("LicenseValidator", "An error has occurred on the licensing server.");
      handleResponse(291, localObject);
      return;
    case 5:
      Log.w("LicenseValidator", "Licensing server is refusing to talk to this device, over quota.");
      handleResponse(291, localObject);
      return;
    case 258:
      Log.w("LicenseValidator", "INVALID_PACKAGE_NAME");
      handleApplicationError(1);
      return;
    case 259:
      Log.w("LicenseValidator", "NON_MATCHING_UID");
      handleApplicationError(2);
      return;
    case 3:
    }
    Log.w("LicenseValidator", "NOT_MARKET_MANAGED");
    handleApplicationError(3);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.android.vending.licensing.LicenseValidator
 * JD-Core Version:    0.6.2
 */